<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加减法计算器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .calculator {
            border: 1px solid #ccc;
            padding: 20px;
            width: 300px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        .input-group {
            margin-bottom: 10px;
        }

        .input-group label {
            display: block;
            margin-bottom: 5px;
        }

        .input-group input {
            width: 100%;
            padding: 8px;
            margin-bottom: 5px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }

        .button-group {
            text-align: right;
        }

        .button-group button {
            padding: 10px 15px;
            margin-left: 5px;
            border: none;
            border-radius: 4px;
            background-color: #4CAF50;
            color: white;
            cursor: pointer;
        }

        .button-group button:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
    <div class="calculator">
        <div class="input-group">
            <label for="number1">数字 1:</label>
            <input type="number" id="number1" name="number1">
        </div>
        <div class="input-group">
            <label for="number2">数字 2:</label>
            <input type="number" id="number2" name="number2">
        </div>
        <div class="button-group">
            <button id="add">+</button>
            <button id="subtract">-</button>
        </div>
        <div class="input-group">
            <label for="result">结果:</label>
            <input type="text" id="result" name="result" readonly>
        </div>
    </div>
    <script>
       let s1= document.querySelector('#number1')
       let s2= document.querySelector('#number2')
       let i1=document.querySelector('#add')
       let i2=document.querySelector('#subtract')
       let jg= document.querySelector('#result')
        i1.addEventListener('click',function(){
            let sum =parseFloat(s1.value)+parseFloat(s2.value)
            jg.value=sum
        })
        i2.addEventListener('click',function(){
            let sum =parseFloat(s1.value)-parseFloat(s2.value)
            jg.value=sum
        })
    </script>
</body>
</html>
